* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file runs additional regressions for export market outcomes.

* Setup
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_mergers_all_largestT_1865.dta", clear
rename aar aar_ori
expand 27
bysort cvrnrA aar_ori cvrnrT: gen aar = 1991 + _n
rename cvrnrT cvrnr
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_firm_subset1865.dta", keep(match) 
collapse (sum) employee_cvrnr OMS_FIRM, by(cvrnrA aar_ori aar)
rename aar aarA
rename aar_ori aar
rename employee_cvrnr employee_cvrnr_tgt
rename OMS_FIRM OMS_FIRM_tgt
tempfile tempe
save `tempe.dta', replace

* Main data
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\regression_data_export.dta", clear

merge 1:1 cvrnrA aar aarA using `tempe.dta', keep(match master)

egen maxaarAin = max(aarA) if _merge==3, by(cvrnrA aar)
egen minaarAin = min(aarA) if _merge==3, by(cvrnrA aar)
drop _merge

gen OMS_FIRM_tgt0 = OMS_FIRM_tgt if aarA==minaarAin
gen OMS_FIRM_tgt1 = OMS_FIRM_tgt if aarA==maxaarAin
egen mOMS_FIRM_tgt0 = mean(OMS_FIRM_tgt0), by(cvrnrA)
egen mOMS_FIRM_tgt1 = mean(OMS_FIRM_tgt1), by(cvrnrA)
gen OMS_FIRM_tgt_gr = (mOMS_FIRM_tgt1/mOMS_FIRM_tgt0-1)

* Figure A.16(d), (e), (f)
foreach x in lnnmark lnnprod {
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=5 & ((acquirer==1 & OMS_FIRM_tgt_gr>0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes 

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=5 & ((acquirer==1 & OMS_FIRM_tgt_gr<=0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes
}

foreach x in lnnprodpermark {
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=5 & ((acquirer==1 & max_merge==3 & OMS_FIRM_tgt_gr>0) | acquirer==0) & _mergedist==3, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes 

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=5 & ((acquirer==1 & max_merge==3 & OMS_FIRM_tgt_gr<=0) | acquirer==0) & _mergedist==3, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes
}
